<?php

require_once('./modules/feeds/feed.inc');

class AddFeedRenderer extends Renderer
{
	function pageLoad()
	{
		switch( $this->action )
		{
			case "add":
				$this->addFeed();
				break;
			case "":
			case "show":
			default:
				break;
		}
	}

	function isPermitted()
	{
		//echo "permission check feeds";
		if ( isset($this->user) && $this->user->type == 2 )
			return true;
		else
			return false;
	}
	
	
	function addFeed()
	{
		$feed = $_POST['txtFeedName'];
		$desc = $_POST['txtDesc'];
		$url =  $_POST['txtUrl'];
		
		$oFeed = new Feed();
		
		$result = $oFeed->add($feed,$desc,$url);
				
		if($result > 0)
			header("Location: index.php?pg=add_feed&status=success");
		else
			header("Location: index.php?pg=add_feed&status=failed");
	}

	function renderBreadcrumbs()
	{
		parent::renderBreadcrumbs();
		
		global $breadcrumbs;
		
		$breadcrumbs .= "&nbsp;&#187;&nbsp;Add feed";
	}
	
	function renderContent()
	{
		global $content;
		global $siteName;
		
		$content = 
		"<div class='headerPitch'>
			<p><h1>Add feed</h1></p>
		</div>
		<div class='pageContentTitle'>
			<p></p>
		</div>
		<div class='pageContent'>
			<p>
			<form method='POST' action='index.php?pg=add_feed&act=add'>
			<fieldset style='width:440px;padding:20px;'>
				<legend>Feed details:</legend>
				name: <input type='text' name='txtFeedName' id='txtFeedName' size='80' /><br />
				description: <input type='text' name='txtDesc' id='txtDesc' size='80' /><br />
				url: <input type='text' name='txtUrl' id='txtUrl' size='80' /><br /><br/>
				<input type='submit' value='Submit'/>";
		if( isset($GET_['status']) && $_GET['status'] == 'failed' )
			$content .= "<P/><label style='color:red;'>Failed to add feed</label>";
		else if(isset($_GET['status']) && $_GET['status'] == "success")
			$content .= "<P/><label style='color:green;'>Feed added successfully</label>";
		
		$content .= "				</fieldset>
			</form>
			</p>
		</div>";
	}
}

$renderer = new AddFeedRenderer();

?>
